Templates already provide a hierarchy to help us organize the code, and for monolithic applications, organize the code according to the project structure description.
But when we have a lot of developers and a lot of services, maybe we get confused. Here to share with you the corresponding solution, the specific use of which solution is determined by the user himself.
Templates provide structure andModules
that help developers organize code very easily, and have some extensibility and anti-interference for collaborative development (according to module division).
Finally, they all provide interface services throughHttp.API
, which is very easy to understand and implement.
To be clear, multi-services here refers to the fact that when a production environment is released, there will be multiple independent and different application services running.
For multiple services, or splitting into microservices, we can have different implementation scenarios, depending on your team!
Important
For the choice of solutions should consider the overall development experience of the team, which is mainly reflected in the development efficiency, implementation difficulty, risk and other aspects, do not sacrifice their own and team energy and time in order to achieve what others call "design patterns".
This programme is very easy to implement and understand, and its main features are as follows:
This scenario makes things simple, assuming we end up deploying three services
Http.API
AdminService
OrderService
This means that we will have threeWebAPI
projects and we will createAdminService
andOrderService
projects inMicroservice
.
We will develop in two ways:
Entity
, and all business logic is implemented inApplication
.Application
project, but define only those interfaces that need to be open to the outside world.This means that projects share all business logic, which is not split and decoupled according to service.
Entity
UserMod
,AdminMod
andOrderMod
modules respectively to implement the business logic (i.e.Manager
) of each module.Http.API
project referencesUserMod
,AdminService
referencesAdminMod
,OrderService
referencesOrderMod
.This allows decoupling of business logic, where services reference only their own business implementations.
Since each module still needs to referenceApplication
project, this means that if there is a common business, it can still be reused, and of course this also means that each service is still not completely independent and decoupled.
We can see that through module segmentation, we can flexibly split business logic and deployment, and at the same time, we can reuse some code to a certain extent. This is sufficient for most cases.
If you must implement more independent and decoupled services, read on!
Before we go into specifics, we need to consider a few practical questions:
This involves collaboration between teams and services, which can be very complex. In order to simplify the problem, we give some qualifications to facilitate a better discussion.
If our team uses a unified language and framework to implement microservices
We'll talk about that earlier. And then we still have some questions:
We still need to assume some scenarios for these questions in order to better discuss them.
- Manage all service codes in one repository (master repository) or as a sub-repository of the master repository if the service has its own repository.
- Manage all projects with one solution.
Working with solutions is a very natural thing for. NET developers, which means you can work on multiple projects in one IDE instance.
Next, suppose we need to followDDD
's microservices practice and keep services separate, how should we implement it?
Let's make a few points clear:
In short, services are almost completely independent. For those that cannot reuse business logic codes, functional codes can be reused through class libraries.
One option is to create a template project for each service and develop it entirely independently.
So how should we coordinate? We can create a separate solution, add service items to that solution, and then use.NET Aspire
for debugging.
Ater.Dry
can also be used to add new standalone services to existing solutions, or you can create your ownHttp
orGRPC
services.
These independent services have their own entity definitions, database contexts, business implementation layers, and interface layers. These hierarchies no longer exist as project
, but as folder
.
This is easy to understand because all code works only within the current service and does not need to be packaged into projects to be referenced by other projects.
Ater.Dry
will automatically discover microservice items under the solution, and code generation can also identify entities in microservices and generate code in corresponding services.
Note
Code generation only supports standalone services created usingDry Studio
because it contains the default file directory hierarchy.
If you use.NET Aspire
for microservice development debugging, manually add the new service toAppHost
after you create it.
Depending on the situation, if your team or business requirements do not require you to split services independently, we recommend that you split business logic in modules.
If you must implement independent services, we recommend that you manage the entire project using a solution that encompasses all services.